#include "BillManager.h"  
#include <iostream>  
#include <algorithm>  
#include <iomanip> 
void BillManager::displayAllBills() const {  
    std::cout << "All Bills:\n";  
    for (const auto& bill : bills_) {  
        std::cout << "Date: " << bill.getDate()  
                  << ", Amount: " << bill.getAmount()  
                  << ", Category: " << bill.getCategory()  
                  << ", Note: " << bill.getNote()  
                  << ", Type: " << (bill.isIncome() ? "Income" : "Expense") << "\n";  
    }  
}  
  
void BillManager::queryBills(const std::string& date, const std::string& startDate, const std::string& endDate, const std::string& category) const {  
    std::cout << "Queried Bills:\n";  
    auto it = bills_.begin();  
    while (it != bills_.end()) {  
        bool matches = true;  
        if (!date.empty() && it->getDate() != date) matches = false;  
        if (!startDate.empty() || !endDate.empty()) {  
        }  
        if (!category.empty() && it->getCategory() != category) matches = false;  
          
        if (matches) {  
            std::cout << "Date: " << it->getDate()  
                      << ", Amount: " << it->getAmount()  
                      << ", Category: " << it->getCategory()  
                      << ", Note: " << it->getNote()  
                      << ", Type: " << (it->isIncome() ? "Income" : "Expense") << "\n";  
        }  
        ++it;  
    }  
}  
  
void BillManager::setMonthlyBudget(double limit) {
    budget_ = Budget(limit);
}
 
double BillManager::getCurrentBudgetBalance() const {
    return budget_.getCurrentBalance();
}
 
void BillManager::resetMonthlyBudget() {
    budget_.resetMonth();
}
 
void BillManager::monthlyStatistics() const {
    double totalIncome = 0;
    double totalExpense = 0;
    std::map<std::string, double> incomeCategories;
    std::map<std::string, double> expenseCategories;
 
    for (const auto& income : incomes_) {
        totalIncome += income.getAmount();
        incomeCategories[income.getCategory()] += income.getAmount();
    }
 
    for (const auto& expense : expenses_) {
        totalExpense += expense.getAmount();
        expenseCategories[expense.getCategory()] += expense.getAmount();
        budget_.addExpense(expense.getAmount());
    }
 
    std::cout << "Monthly Statistics:\n";
    std::cout << "Total Income: " << totalIncome << "\n";
    std::cout << "Total Expense: " << totalExpense << "\n";
    std::cout << "Remaining Budget: " << getCurrentBudgetBalance() << "\n";
    std::cout << "Income Categories:\n";
    for (const auto& pair : incomeCategories) {
        std::cout << "  " << pair.first << ": " << pair.second << "\n";
    }
    std::cout << "Expense Categories:\n";
    for (const auto& pair : expenseCategories) {
        std::cout << "  " << pair.first << ": " << pair.second << "\n";
    }
}
